<!DOCTYPE HTML>
<html lang="cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <%include("/common/header.html",{title:''}){}%>
    <title>商品列表</title>
    <link rel="stylesheet" href="css/formSelects-v4.css" />
</head>
<body>

<div class="x-nav" style="margin: 20px auto auto 15px;">
      <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
        <a href="javascript:;">首页</a><span lay-separator="">/</span>
        <a href="javascript:;">提现管理</a><span lay-separator="">/</span>
        <a><cite>提现订单</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="margin: -5px 14px 0px 0px;float:right;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3"></i>
    </a>
</div>

<div class="layui-form layui-card-header layuiadmin-card-header-auto">
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-block">
                <select type="text" name="classify" id="search" autocomplete="off" class="layui-select">
                    <option>请选择</option>
                    <option value="">审核通过</option>
                    <option value="">驳回</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
        </div>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
            <script type="text/html" id="toolbarDemo">
            </script>
            <script type="text/html" id="imgTpl">
                <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
            </script>
            <script type="text/html" id="table-useradmin-webuser">
                {{#  if(d.status === 1){ }}
                <a class="layui-btn  layui-btn-xs" lay-event="confirm"><i
                        class="layui-icon layui-icon-template"></i>确认付款</a>
                {{#  }else{ }}
                <a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="null"><i
                        class="layui-icon layui-icon-template"></i>已付款</a>
                {{#  } }}
            </script>
        </div>
    </div>
</div>
<!-- 单个商品弹出页面 -->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin"
     id="layuiadmin-form-useradmin"
     style="padding: 15px;display: none">
    <form action class="layui-form" lay-filter="component-form-element" id="myform">
        <input type="hidden" name="agent_id" id="aid" value="${session.om_user.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">提现人</label>
            <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话:</label>
            <div class="layui-input-inline">
                <input type="text" name="phone"  lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">地址:</label>
            <div class="layui-input-inline">
                <input type="text" name="address" readonly="readonly" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">提现金额:</label>
            <div class="layui-input-inline">
                <input type="text" name="withMoney" readonly="readonly" lay-verify="required"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开户行:</label>
            <div class="layui-input-inline">
                <input type="text" name="bankName" readonly="readonly" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">银行卡号:</label>
            <div class="layui-input-inline">
                <input type="text" name="bankNum" readonly="readonly" lay-verify="required" class="layui-input">
            </div>
        </div>
    </form>
</div>



<%include("/common/foot.html"){}%>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script src="js/formSelects-v4.js" type="text/javascript" charset="utf-8"></script>
<script>

    layui.use(['index', 'table', 'form', 'laydate', 'layedit', 'AjaxCommon', 'AliangLayui'], function () {
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var upload = layui.upload;
        var layedit = layui.layedit;
        var AliangLayui = layui.AliangLayui;
        var index;

        //富文本编辑器
        layedit = layui.layedit;

        var title = "提现订单";
        var size = ['100%', '100%']
        var findAll_url = 'orderWith/findFinAll.jhtml';
        var update_url = 'orderWith/apply.jhtml';
        var delete_url = 'orderWith/delete.jhtml';
        var findMoney_url="orderWith/findMoney.jhtml";

        var cols = [ //表头
            {checkbox: true, fixed: true},
            {field: 'withMoney',  title: '提现金额'},
            {field: 'name',  title: '提现人姓名'},
            {field: 'phone',  title: '提现人手机号'},
            {field: 'address',  title: '地址'},
            {field: 'bankName',title: '开户行'},
            {field:'bankNum',title: '银行卡号'},
            {field: 'withTime',  title: '提现时间'},
            {title: '操作',  toolbar: '#table-useradmin-webuser', fixed: 'right'}
        ];


        AliangLayui.createTable(
            "#LAY-user-manage",
            "listReload",
            "#toolbarDemo",
            title,
            findAll_url,
            true,
            [10, 15, 20, 25],
            ['filter', 'print', 'exports'],
            cols,
            null
        );

        //初始化日期模块
        laydate.render({
            elem: '#create' //指定元素
        });
        //弹出修改页面调用初始化数据方法
        function initUpdate() {
            layer.open({
                title: title,
                area: size,
                type: 1,
                content: $('#layuiadmin-form-useradmin'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                btn: ['关闭'], //可以无限个按钮
                cancel: function (index, layero) {//取消事件
                    location.replace(location.href);　//layer.open关闭刷新
                },
            });
            var agent_id=$("#aid").val()
            // alert(typeof agent_id)
            $.ajax({
                url:findMoney_url,
                type: "POST",
                data: {
                    "aid":Number(agent_id)
                },
                dataType: "json",
                success: function (ret) {
                    console.log(JSON.stringify(ret.data))
                    layui.form.val("component-form-element", loadData(ret.data));
                }
            })
        }

        function loadData(data) {
            var ret={
                "name":data.name,
                "phone":data.phone,
                "address":data.address,
                "bankName":data.bankName,
                "bankNum":data.bankNum,
                "withMoney":data.withMoney
            }
            if (data.withdrawalMoney==0){
                $("#demo").hide()
                $("#with").attr("readonly",'readonly');
            }
            $("#daiti").val(data.withdrawalMoney)
            return ret;
        }

        function initUpdates(data) {
            layer.open({
                title: title,
                area: size,
                type: 1,
                content: $('#layuiadmin-form-useradmins'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                btn: ['关闭'], //可以无限个按钮
                cancel: function (index, layero) {//取消事件
                    location.replace(location.href);　//layer.open关闭刷新
                },
            });
            layui.form.val("component-form-elements", loadDatas(data));

        }




        //修改页面的内容提交到后台处理
        form.on('submit(component-form-element)', function (data) {
            data.field.content = layedit.getContent(index);
            postUpdate(data);
            return false;
        });
        //头工具栏事件
        table.on('toolbar(LAY-user-manage)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    initUpdate(0);
                    break;
                case 'combination':
                    initUpdates(0);
                    break;
                case 'export':
                    layer.msg("导出");
                    break;
            }
        });

        //点击每行右工具栏“操作”里面按钮效果
        table.on('tool(LAY-user-manage)', function (obj) {
            var data = obj.data;
            if (obj.event === 'confirm') {
                initConfirm(data.id)
            } else if (obj.event === 'edit') {
                layer.msg("审核通过")
            } else if (obj.event === 'del') {
                initUpdate(data);
                // layer.confirm('删除以后数据将不能恢复，确定删除吗？', function (index) {
                //     //alert(data.id);
                //     postDelete(data.id);
                // });
            }
        });
        var confirm_url="orderWith/confirm.jhtml";
        function initConfirm(data){
            $.ajax({
                url:confirm_url,
                type: "POST",
                data: {
                    "id":data
                },
                dataType: "json",
                success: function (ret) {
                    table.reload('listReload');
                }
            })
        }


        //监听搜索按钮效果
        form.on('submit(LAY-user-front-search)', function (data) {
            var field = data.field;
            table.reload('listReload', {
                where: {
                    name: field.name,
                    price: field.price,
                    pay: field.pay
                },
                page: {
                    curr: 1
                }
            });
        });

        //ajax提交删除内容
        window.postDelete = function (id) {
            $.ajax({
                url: delete_url,
                type: "POST",
                data: {
                    "id": id
                },
                dataType: "json",
                success: function (ret) {
                    if (ret == null) {
                        layer.msg("删除失败", {
                            icon: 5
                        });
                    } else {
                        layer.msg("删除成功", {
                            icon: 6
                        });
                        layer.closeAll();
                        table.reload('listReload');
                    }
                    return ret;
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    var estr = "Page:" + window.location.pathname + ",Function: postDelete()";
                    layer.open({
                        title: "错误信息",
                        area: ['100%', '100%'],
                        type: 2,
                        content: "base/error.jhtml?info=" + estr, //
                        btn: ['关闭'] //可以无限个按钮
                    });
                }
            });
        }

        window.postUpdate = function (data) {
            var formData = new FormData();
            formData.append("data", JSON.stringify(data.field));
            $.ajax({
                url: update_url,
                type: "POST",
                //traditional:true,
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code == 0) {
                        layer.closeAll();
                        layer.msg(data.msg, {time: 600, icon: 1}, function () {
                            //table.reload('listReload');

                        });
                        location.replace(location.href);
                    } else {
                        layer.msg(data.msg, {icon: 6});
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    var estr = "Page:" + window.location.pathname + ",Function:postUpdate()";
                    layer.open({
                        title: "错误信息",
                        type: 2,
                        content: "base/error.jhtml?info=" + estr,
                        btn: ['关闭'] //可以无限个按钮
                    });
                }
            });
        }
    });

</script>
</body>

</html>